$(() => {
    let isPcWin = window.location.pathname.endsWith("pc.html");
    let isSubWin = window.parent !== window || isPcWin;
    let tabs = [
        [
            ['feed.html', '#icon-bar-feed', '喂猫'],
            ['cloud-cat.html', '#icon-bar-cloud-cat', '云猫'],
            ['knowledge.html', '#icon-bar-knowledge', '科普'],
            ['me.html', '#icon-bar-me', '我的']
        ],
        []
    ];
    let oldtabs = tabs;
    let pathname = isPcWin ? 0 : window.location.pathname;
    for (let y in oldtabs) {
        y = tabs[y]
        for (let x in y) {
            if (pathname == x || pathname.toString().endsWith(y[x][0])) {
                tabs = y;
                break;
            }
        }
        if (y === tabs) break;
    }
    if (oldtabs === tabs) return;
    let elements = '';
    for (let x in tabs) {
        x = tabs[x];
        let js = x[3] || isSubWin;
        let track = `_hmt && _hmt.push(['_trackEvent', 'foot-tab', '${x[3]?'ban':'go'}','${x[2]}']);`;
        let click = x[3] ? `alert('暂未开放 ${x[2]} 页面');` : `showContent('${x[0]}')`;
        elements += `<a${pathname.endsWith(x[0])?' class="active"':""} href="${js?'javascript:void(0);':x[0]}" onclick="${track}${js?click:''}" ><svg class="icon" aria-hidden="true"><use xlink:href="${x[1]}"></use></svg><span>${x[2]}</span></a>`;
    }
    if (!isSubWin) {
        $(document.body).append(`<div class="tab-bar">${elements}</div>`);
        //占位符
        if ($(".tab-bar-blank").length > 0)
            $(".tab-bar-blank").html('&nbsp;');
        else
            $(".main-content").append('<div class="tab-bar-blank">&nbsp;</div>');
    } else {
        $(window.parent.document.getElementById("navContent")).html(elements);
    }
});